#!/bin/bash
status()
{
	pid=$(pidof $1 2>/dev/null)
	rtrn=$?
	if [ $rtrn -ne 0 ]; then
		echo "$1 is stopped"
	else
		echo "$1 (pid $pid) is running..."
	fi
	return $rtrn
}
stop()
{
	desc="Pacemaker Remote"
	prog=$1
	shutdown_prog=$prog

	if status $shutdown_prog > /dev/null 2>&1; then
	    kill -TERM $(pidof $prog) > /dev/null 2>&1

	    while status $prog > /dev/null 2>&1; do
		sleep 1
		echo -n "."
	    done
	else
	    echo -n "$desc is already stopped"
	fi

	rm -f /var/lock/subsystem/pacemaker
	rm -f /var/run/${prog}.pid
	killall -q -9 pacemakerd pacemaker-attrd pacemaker-based \
		pacemaker-controld pacemaker-execd pacemaker-fenced \
		pacemaker-schedulerd pacemaker-remoted
}

stop "pacemaker-remoted"
exit 0
